package com.imooc.service;

import com.imooc.bean.Message;
import com.imooc.dao.MessageDao;
import com.imooc.entity.Page;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 查询相关业务功能
 *
 * @author xiaoming
 * @version 1.0
 * @date 2018-11-05 22:31
 **/
public class QueryService {

    public List<Message> queryMessage(String command, String description) {
        MessageDao messageDao = new MessageDao();
        return messageDao.queryMessage(command, description);
    }

    /**
     * 分页查询
     *
     * @param command
     * @param description
     * @param page
     */
    public List<Message> queryMessageByPage(String command, String description, Page page) {
        Map<String, Object> parameter = new HashMap<String, Object>();
        Message message = new Message();
        message.setCommand(command);
        message.setDescription(description);

        MessageDao messageDao = new MessageDao();
        int totalNumber = messageDao.count(message);
        page.setTotalNumber(totalNumber);
        parameter.put("message", message);
        parameter.put("page", page);

        // 分页查询并返回结果
        return messageDao.queryMessageListByPage(parameter);
    }

}

